package com.mailbox.mailbox.util.SendEmail;

import java.security.SecureRandom;
import java.util.Random;

/**
 * @author 张铭辉
 */
public class VerCodeGenerateUtil {
    //验证码包含的字段，可自己设置
    private static final String SYMBOLS = "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
    private static final Random RANDOM = new SecureRandom();
    //    生成 6 位数的随机数字
    public static String generateVerCode() {
        //	如果是六位，就生成大小为 6 的数组
        char[] numbers = new char[6];
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(numbers);
    }

    public static boolean emailRegular(String email,String nums){
        String username = email + nums;
        if(nums.equals("@qq.com")){
            String qqStr = "[1-9]\\d{4,9}@qq\\.com";
            return username.matches(qqStr);
        }else if(nums.equals("@163.com")){
            String str163 = "^[A-Za-z]\\w{5,17}@(vip\\.(126|163|188)\\.com|163\\.com|126\\.com|yeach\\.net)";
            return username.matches(str163);
        }else{
            return false;
        }
    }
}
